package com.bjpowernode.mvc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bjpowernode.db.domain.Recharge;
import com.bjpowernode.db.mapper.RechargeMapper;
import com.bjpowernode.mvc.service.inter.RechargeService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@RequiredArgsConstructor
@Service
public class RechargeServiceImpl implements RechargeService {

    private final RechargeMapper rechargeMapper;


    /**
     * 查询最近充值记录
     *
     * @param uid
     * @param pageNo
     * @param pageSize
     * @return
     */
    @Override
    public List<Recharge> queryRechargeByUid(Integer uid, Integer pageNo, Integer pageSize) {
        QueryWrapper<Recharge> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("uid", uid).orderByDesc("recharge_time");
        //.last("limit" + offset + "," + pageSize)

        //获取分页结果
        Page<Recharge> rechargePage = rechargeMapper.selectPage(Page.of(pageNo, pageSize), queryWrapper);
        return rechargePage.getRecords();
    }
}
